package com.qinglei.recoup.longconn.service.impl;

import com.qinglei.recoup.longconn.entity.Message;
import com.qinglei.recoup.longconn.entity.MessageV4_1;
import com.qinglei.recoup.longconn.service.FileService;
import com.qinglei.recoup.longconn.service.FileStorage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Slf4j
@Service
public class LocalFileServiceImpl implements FileService {

    @Autowired
    private Map<String, FileStorage> fileStorageMap;

    /**
     * 保存设备上传数据
     *
     * @param msg
     */
    @Override
    public void save(Message msg) {
        FileStorage fileStorage = fileStorageMap.get("prj" + msg.getProjectCode());
        fileStorage.save(msg);
    }

    /**
     * 设备下线，删除设备
     *
     * @param sn
     */
    @Override
    public void procDeviceOffline(String sn) {
        throw new RuntimeException("procDeviceOffline not support");
    }

    @Override
    public void save(MessageV4_1 messageV4_1) {
        FileStorage fileStorage = fileStorageMap.get("prj3");
        fileStorage.save(messageV4_1);
    }

    @Override
    public void save(Object message) {
        FileStorage fileStorage = fileStorageMap.get("common");
        fileStorage.save(message);
    }

}
